﻿package rob.ui{
	import rob.ui.KeyController;
	import rob.ui.MouseController;
	import rob.core.World3d;
	
	public class UserInput{
		private var _world:World3d;
		private var _keys:KeyController;
		private var _mouse:MouseController;
		
		public function UserInput(world:World3d):void{
			_world = world;
			_keys = KeyController.instance;
			_mouse = MouseController.instance;
		}
		
		public function tick():void{
			// keyboard
			_keys.tick();
			var dr:Number = 10, dtheta = Math.PI/64;
			
			if		(_keys.camLeft) 	_world.camMoveRel(-dr,0,0);
			else if	(_keys.camRight)	_world.camMoveRel(dr,0,0);
			else if	(_keys.camUp)		_world.camMoveRel(0,dr,0);
			else if	(_keys.camDown)		_world.camMoveRel(0,-dr,0);
			else if (_keys.keyE){
				_world.rotateBy(dtheta);
			}
			else if (_keys.keyQ) {
				_world.rotateBy(-dtheta);
			}
			
			// mouse
			var dz:Number = 50;
			if(_mouse.scrolled){
				if(_mouse.delta > 0){
					_world.zoomBy(-dz);
				}
				else if(_mouse.delta < 0){
					_world.zoomBy(dz);
				}
			}
			if(_mouse.moved){
				//trace("moved");
			}
			
			_mouse.reset();
		}
		
	}
}